{extend name="base" /}
{block name="header"}
<div class="admin_header_{$skin_name|default='default'} clearfix">
    <div class="title"><i></i>{$title|default=""}</div>
    <div class="action">
        <b></b>
        <div class="layui-btn-group layui-btn-group-only">
            <a class="layui-btn  layui-btn-disabled layui-btn-sm "><i class="fa fa-reply"></i> 返 回 </a>
        </div>
    </div>
</div>

{/block}
{block name="main"}
<blockquote class="layui-elem-quote quoteBox">
    <form class="layui-form">
        {notempty name="$buttonSearch"}
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" class="layui-input searchVal" placeholder="请输入搜索的内容" />
            </div>
            {$buttonSearch|showButton|raw}
        </div>
        {/notempty}
        <div class="layui-inline">
            {$buttonAdd|showButton|raw}
        </div>
        {notempty name="$buttonDelete"}
        <div class="layui-inline">
            {$buttonDelete|showButton|raw}
        </div>
        {/notempty}
    </form>
</blockquote>
<form class="layui-form" id="layui_form">
    {$table|showTable|raw}
    <div style="display: none">
        {$buttonBar|showButtonGroup|raw}
    </div>

</form>

{/block}
{block name="script"}
<script type="text/javascript">
    layui.use(['layer','table', 'form'], function() {
        var layer = parent.layer === undefined ? layui.layer : top.layer,
                $ = layui.jquery,
                form = layui.form,
                table = layui.table;

        //列表操作
        table.on('tool({$table.id})', function(obj){
            var layEvent = obj.event,
                    data = obj.data;

            if(layEvent === 'edit'){ //编辑
                addAction(data);
            }else if(layEvent === 'usable'){ //启用禁用
                var _this = $(this),
                        usableText = "是否确定禁用此用户？",
                        btnText = "禁用";
                if(data.status=="0"){
                    usableText = "是否确定启用此用户？";
                            btnText = "启用";
                }else if(data.status =="1"){
                    usableText = "是否确定禁用此用户？";
                    btnText = "禁用";
                }
                layer.confirm(usableText,{
                    icon: 3,
                    title:'系统提示',
                    cancel : function(index){
                        layer.close(index);
                    }
                },function(index){
                    $.get("{:url('usable')}",{
                        id : data.id,
                        status : data.status //将需要删除的newsId作为参数传入
                    },function(res){
                        layer.msg(res.msg);
                        tableIns.reload();
                        layer.close(index);
                    })
                },function(index){
                    layer.close(index);
                });
            }else if(layEvent === 'delete'){ //删除
                layer.confirm('确定删除此用户？',{icon:3, title:'提示信息'},function(index){
                     $.get("{:url('delete')}",{
                         id : data.id  //将需要删除的newsId作为参数传入
                     },function(res){
                         layer.msg(res.msg);
                    tableIns.reload();
                    layer.close(index);
                     })
                });
            }
        });

        {notempty name="$buttonGroup"}
        {foreach $buttonGroup.button as $key=>$vo }
        $('.{$buttonGroup.id}_{$key}').click(function(){
            var id = $(this).attr('id');
            $.ajax({
                url:"{$vo.href}",
                data:$('#layui_form').serialize(),
                type:'post',
                async: false,
                success:function(res) {
                    if(res.code == 1) {
                        layer.alert(res.msg, function(index){
                            location.href = res.url;
                        })
                    } else {
                        layer.msg(res.msg);
                    }
                }
            })
        });
        {/foreach}
        {/notempty}


        var tableIns = table.render({
            elem: "#{$table.id}",
            url : "{$table.url}",
            cellMinWidth : "{$table.cellMinWidth}",
            page : true,
            limits : [10,15,20,25],
            id : "{$table.id}",
            cols : [[
{foreach $table.cols as $key=>$vo }
                {field: "{$vo.field}"{notempty name="$vo.title"},title:"{$vo.title}"{/notempty}
                    {notempty name="$vo.minWidth"},minWidth:"{$vo.minWidth}"{/notempty}
                    {notempty name="$vo.align"},align:"{$vo.align}"{/notempty}
                    {notempty name="$vo.type"},type:"{$vo.type}"{/notempty}
                    {notempty name="$vo.templet"},templet:{$vo.templet|raw}{/notempty}
                    {notempty name="$vo.width"},width:{$vo.width}{/notempty}
                    {notempty name="$vo.fixed"},fixed:"{$vo.fixed}"{/notempty}
                    {notempty name="$vo.LAY_CHECKED"},LAY_CHECKED:"{$vo.LAY_CHECKED}"{/notempty}
                    {notempty name="$vo.sort"},sort:"{$vo.sort}"{/notempty}
                    {notempty name="$vo.unresize"},unresize:"{$vo.unresize}"{/notempty}
                    {notempty name="$vo.event"},event:"{$vo.event}"{/notempty}
                    {notempty name="$vo.style"},style:"{$vo.style}"{/notempty}},
{/foreach}
            ]]
        });

        //添加用户
        function addAction(edit){
            var index = layui.layer.open({
                title : "{$buttonAdd.0.title}",
                type : 2,
                content : "./add.html",
                success : function(layero, index){
                    var body = layui.layer.getChildFrame('body', index);
                    if(edit){
                        {notempty name="$table"}
                        {foreach $table.cols as $key=>$vo }
                        {notempty name="$vo.field"}
                        {if $vo.type eq "radio"}
                        body.find(".{$vo.field}").prop("checked","checked");
                        {else /}
                        body.find("#{$vo.field}").val(edit.{$vo.field});
                        {/if}
                        {/notempty}
                        {/foreach}
                        {/notempty}
                        form.render();
                    }
                    setTimeout(function(){
                        layui.layer.tips('点击此处返回列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },100)
                }
            });
            layui.layer.full(index);
            window.sessionStorage.setItem("index",index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize",function(){
                layui.layer.full(window.sessionStorage.getItem("index"));
            })
        }
        $(".addAction_btn").click(function(){
            addAction();
        });
    });
</script>
{/block}